package typejump.commands;

import java.awt.event.KeyEvent;

import typejump.Messenger;
import typejump.Settings;
import typejump.TypeJump;
import typejump.engine.GameEngine;
import typejump.engine.OnGoingThing;

public class DevEnablePanning implements TextCommand, OnGoingThing {

	private double speed = Settings.getDouble("player.cheatspeed");

	@Override
	public boolean matches(String command) {
		return command.matches("dev [ed]p");
	}

	@Override
	public void act(String command) {
		if (command.contains("ep")) {
			GameEngine.setFocusOnPlayer(false);
			GameEngine.addOnGoingThing(this);
			GameEngine.addTextEffect("ENABLE PANNING", "dev");
			Messenger.addBriefMessage("disable arrow keys");
		} else if (command.contains("dp")) {
			Messenger.addBriefMessage("disable panning");
			GameEngine.addTextEffect("DISABLE PANNING", "dev");
		}
	}

	@Override
	public boolean happen(TypeJump tj, double seconds) {
		if (Messenger.consumeMessage("disable panning"))
			return true;
		
		double mod = speed * seconds;
		
		if (tj.isKeyDown(KeyEvent.VK_LEFT)) {
			GameEngine.modTranslate( mod, 0);
		} else if (tj.isKeyDown(KeyEvent.VK_RIGHT)) {
			GameEngine.modTranslate(-mod, 0);
		}
		
		if (tj.isKeyDown(KeyEvent.VK_UP))
			GameEngine.modTranslate(0,  mod);
		else if (tj.isKeyDown(KeyEvent.VK_DOWN))
			GameEngine.modTranslate(0, -mod);
		
		return false;
	}

}
